#ifndef DB_CLIENT_H
#define DB_CLIENT_H
#include <string>
#include "db_connection_handler.h"
#include "db_connection.h"
class Service;
class DBConnection;
class DBClientHandler;
class JMsgProto;
class DBClient : public DBConnectionHandler
{
public:
	DBClient(Service* service, std::string host, int port);	
	~DBClient(void);

	void validatePlayerLogin(const std::string& playerId, const std::string& password, bool isGuest);
	void setHandler(DBClientHandler* handler);

	template<class T>
	void sendMsg(T& msg) {
		JMsgWriter writer;
		msg.encode(m_proto, &writer);
		m_dbconn->sendData(writer.getBuffer(), writer.getBufferLen());
	}
public:
	virtual void onDBConnectionData(void* data, int len);
private:
	DBConnection* m_dbconn;
	Service* m_service;
	JMsgProto* m_proto;
	DBClientHandler* m_handler;
};
#endif
